package com.jrx.anytxn.customer.controller;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.customer.dto.coupon.TlCouponDetailRes;
import com.jrx.anytxn.customer.service.ICouponDetailService;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "页面优惠券发放明细接口")
@RestController
@RequestMapping(value = "/customer/couponDetail")
public class CouponDetailController {

    private static final Logger logger = LoggerFactory.getLogger(CouponDetailController.class);

    @Autowired
    private InfoService infoService;
    @Autowired
    private ICouponDetailService couponDetailService;

    @ApiOperation(value = "分页查询优惠券发放明细信息", notes = "分页查询优惠券发放明细信息")
    @GetMapping(value = "/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true)})
    public TxnRespResult<TxnPage<TlCouponDetailRes>> getAllPageByTenId(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize,
                                                                       @RequestParam String beginDate, @RequestParam String endDate,
                                                                       @RequestParam String chineseName, @RequestParam String customerId, @RequestParam String idNumber,
                                                                       @RequestParam String updateBy, @RequestParam String mobile) {
        TxnRespResult<TxnPage<TlCouponDetailRes>> result = new TxnRespResult<>();
        TxnPage<TlCouponDetailRes> response;
        try {
            String tenantId=String.valueOf(infoService.getUser().getProjectId());
            response = couponDetailService.findAllPageByTenantId(pageNum, pageSize, tenantId,chineseName,customerId,idNumber,updateBy,mobile,beginDate,endDate);
            result.getSuccess(response);
        } catch (TxnException e) {
            logger.error(e.getMessage(),e);
            result.getFail(e.getErrCode(), e.getMessage());
        }
        return result;
    }
}
